package common

import (
	"github.com/nknorg/nkn/v2/api/common/errcode"
)

func join(s Serverer, params map[string]interface{}) map[string]interface{} {
	addr, ok := params["addr"].(string)
	if !ok {
		return respPacking(errcode.INVALID_PARAMS, "addr should be a string")
	}
	if addr == "" {
		return respPacking(errcode.INVALID_PARAMS, "length of params is less than 1")
	}
	n := s.GetNetNode()
	b, err := n.Join(addr)
	if err != nil {
		return respPacking(errcode.INTERNAL_ERROR, err.Error())
	}
	return respPacking(errcode.SUCCESS, b)
}
